package com.example.httplibrary.rx.subscriber;

import android.content.Context;
import android.util.Log;


import com.example.httplibrary.exception.ExceptionHandle;

import io.reactivex.disposables.Disposable;


/**
 * Author: 李巷阳
 * Date: 2020/6/1
 * Description: 错误处理订阅
 */
public abstract  class ErrorHandlerSubscriber<T> extends DefualtSubscriber<T> {


    protected ExceptionHandle mErrorHandler = null;

    protected Context mContext;

    public ErrorHandlerSubscriber(Context context){

        this.mContext = context;


        mErrorHandler = new ExceptionHandle();

    }


    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onError(Throwable e) {

        ExceptionHandle.ResponeThrowable baseException =  mErrorHandler.handleException(e);

        if(baseException==null){
            e.printStackTrace();
            Log.d("ErrorHandlerSubscriber",e.getMessage());
        }
        else {

            mErrorHandler.showErrorMessage(baseException);
//            if(baseException.getCode() == BaseException.ERROR_TOKEN){
//                toLogin();
//            }

        }

    }

    private void toLogin() {

//        Intent intent = new Intent(mContext, LoginActivity.class);
//        mContext.startActivity(intent);
    }


}
